﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace ExcelDnaDemo
{
    /// <summary>
    /// 任务窗格使用的自定义窗体控件
    /// </summary>
    [ComVisible(true)]    
    public class CTPControls : UserControl
    {
        //所有的CTP都用同一个字典记录User,在ServerManager中的DicClientIDName

        private Label LblUserStatus;
         
        private RichTextBox RtbMsg;
        private Label LblStatus;

        public CTPControls()
        {
            InitializeComponent();

            this.Disposed += CTPControls_Disposed;
        }

        private void CTPControls_Disposed(object sender, EventArgs e)
        {
            
        }


        private void DelegateOutputMessage(string Message,bool newline=true)
        {
            Invoke(new MethodInvoker(delegate ()
            {
                if (RtbMsg != null && RtbMsg.IsHandleCreated)
                {
                    if (newline) Message += Environment.NewLine;
                    RtbMsg.AppendText(Message);                    
                    RtbMsg.ScrollToCaret();
                }
            }));
        }

        private void InitializeComponent()
        {
            this.LblUserStatus = new System.Windows.Forms.Label();
            this.LblStatus = new System.Windows.Forms.Label();
            this.RtbMsg = new System.Windows.Forms.RichTextBox();
            this.SuspendLayout();
            // 
            // LblUserStatus
            // 
            this.LblUserStatus.AutoSize = true;
            this.LblUserStatus.Location = new System.Drawing.Point(3, 8);
            this.LblUserStatus.Name = "LblUserStatus";
            this.LblUserStatus.Size = new System.Drawing.Size(29, 12);
            this.LblUserStatus.TabIndex = 1;
            this.LblUserStatus.Text = "窗格";
            // 
            // LblStatus
            // 
            this.LblStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.LblStatus.AutoSize = true;
            this.LblStatus.Location = new System.Drawing.Point(3, 583);
            this.LblStatus.Name = "LblStatus";
            this.LblStatus.Size = new System.Drawing.Size(29, 12);
            this.LblStatus.TabIndex = 5;
            this.LblStatus.Text = "就绪";
            // 
            // RtbMsg
            // 
            this.RtbMsg.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.RtbMsg.Dock = System.Windows.Forms.DockStyle.Fill;
            this.RtbMsg.Location = new System.Drawing.Point(0, 0);
            this.RtbMsg.Name = "RtbMsg";
            this.RtbMsg.Size = new System.Drawing.Size(258, 200);
            this.RtbMsg.TabIndex = 3;
            this.RtbMsg.Text = "";
            // 
            // CTPControls
            // 
            this.Controls.Add(this.LblStatus);
            this.Controls.Add(this.LblUserStatus);
            this.Name = "CTPControls";
            this.Size = new System.Drawing.Size(258, 600);
            this.ResumeLayout(false);
            this.PerformLayout();

        }
    }
}
